﻿using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Xml.Serialization;
using CodeSnippet.Options;
using CodeSnippet.Properties;

namespace CodeSnippet.Config
{
    /// <summary>
    /// Style section of the Code Snippet plugin configuration.
    /// </summary>
    [DefaultProperty("SectionName")]
    public class StyleConfig : IStyleConfig, IConfigSection
    {
        #region Properties
        /// <summary>
        /// Gets the name of the section.
        /// </summary>
        /// <value>The name of the section.</value>
        [LocalizedCategory("CategoryAttribute_Attributes"), LocalizedDisplayName("DisplayNameAttribute_SectionName"), LocalizedDescription("DescriptionAttribute_SectionName"), XmlIgnore]
        public string SectionName
        {
            get { return Resources.ConfigSectionName_Styles; }
        }
        /// <summary>
        /// Gets the image.
        /// </summary>
        /// <value>The image.</value>
        [Browsable(false), XmlIgnore]
        public Bitmap Image
        {
            get { return Resources.style; }
        }
        /// <summary>
        /// Flag indicating whether or not lines will have alternating background colors. Default is <c>false</c>.
        /// </summary>
        [Category("Format"), LocalizedDisplayName("DisplayNameAttribute_AlternateLines"), LocalizedDescription("DescriptionAttribute_AlternateLines")]
        public bool AlternateLines { get; set; }
        /// <summary>
        /// Flag indicating whether or not the CSS styles used will be embedded with the HTML output. Default is <c>false</c>.
        /// </summary>
        [Category("Format"), LocalizedDisplayName("DisplayNameAttribute_EmbedStyles"), LocalizedDescription("DescriptionAttribute_EmbedStyles")]
        public bool EmbedStyles { get; set; }
        /// <summary>
        /// Flag indicating whether or not line numbers are generated. Default is <c>false</c>.
        /// </summary>
        [Category("Format"), LocalizedDisplayName("DisplayNameAttribute_LineNumbers"), LocalizedDescription("DescriptionAttribute_LineNumbers")]
        public bool LineNumbers { get; set; }
        /// <summary>
        /// Flag indicating whether or not to use a container for the generated code. Default is <c>false</c>.
        /// </summary>
        [Category("Format"), LocalizedDisplayName("DisplayNameAttribute_UseContainer"), LocalizedDescription("DescriptionAttribute_UseContainer")]
        public bool UseContainer { get; set; }
        /// <summary>
        /// Gets or sets the alt style.
        /// </summary>
        /// <value>The alt style.</value>
        [LocalizedCategory("CategoryAttribute_Styles"), LocalizedDescription("DescriptionAttribute_AltStyle"), Editor(typeof(StyleEditor), typeof(UITypeEditor)), TypeConverter(typeof(StyleConverter))]
        public string AltStyle { get; set; }
        /// <summary>
        /// Gets or sets the alteven style.
        /// </summary>
        /// <value>The alteven style.</value>
        [LocalizedCategory("CategoryAttribute_Styles"), LocalizedDescription("DescriptionAttribute_AltevenStyle"), Editor(typeof(StyleEditor), typeof(UITypeEditor)), TypeConverter(typeof(StyleConverter))]
        public string AltevenStyle { get; set; }
        /// <summary>
        /// Gets or sets the ASP style.
        /// </summary>
        /// <value>The ASP style.</value>
        [LocalizedCategory("CategoryAttribute_Styles"), LocalizedDescription("DescriptionAttribute_AspStyle"), Editor(typeof(StyleEditor), typeof(UITypeEditor)), TypeConverter(typeof(StyleConverter))]
        public string AspStyle { get; set; }
        /// <summary>
        /// Gets or sets the attr style.
        /// </summary>
        /// <value>The attr style.</value>
        [LocalizedCategory("CategoryAttribute_Styles"), LocalizedDescription("DescriptionAttribute_AttrStyle"), Editor(typeof(StyleEditor), typeof(UITypeEditor)), TypeConverter(typeof(StyleConverter))]
        public string AttrStyle { get; set; }
        /// <summary>
        /// Gets or sets the CLS style.
        /// </summary>
        /// <value>The CLS style.</value>
        [LocalizedCategory("CategoryAttribute_Styles"), LocalizedDescription("DescriptionAttribute_ClsStyle"), Editor(typeof(StyleEditor), typeof(UITypeEditor)), TypeConverter(typeof(StyleConverter))]
        public string ClsStyle { get; set; }
        /// <summary>
        /// Gets or sets the code style.
        /// </summary>
        /// <value>The code style.</value>
        [LocalizedCategory("CategoryAttribute_Styles"), LocalizedDescription("DescriptionAttribute_CodeStyle"), Editor(typeof(StyleEditor), typeof(UITypeEditor)), TypeConverter(typeof(StyleConverter))]
        public string CodeStyle { get; set; }
        /// <summary>
        /// Gets or sets the HTML style.
        /// </summary>
        /// <value>The HTML style.</value>
        [LocalizedCategory("CategoryAttribute_Styles"), LocalizedDescription("DescriptionAttribute_HtmlStyle"), Editor(typeof(StyleEditor), typeof(UITypeEditor)), TypeConverter(typeof(StyleConverter))]
        public string HtmlStyle { get; set; }
        /// <summary>
        /// Gets or sets the KWRD style.
        /// </summary>
        /// <value>The KWRD style.</value>
        [LocalizedCategory("CategoryAttribute_Styles"), LocalizedDescription("DescriptionAttribute_KwrdStyle"), Editor(typeof(StyleEditor), typeof(UITypeEditor)), TypeConverter(typeof(StyleConverter))]
        public string KwrdStyle { get; set; }
        /// <summary>
        /// Gets or sets the lnum style.
        /// </summary>
        /// <value>The lnum style.</value>
        [LocalizedCategory("CategoryAttribute_Styles"), LocalizedDescription("DescriptionAttribute_LnumStyle"), Editor(typeof(StyleEditor), typeof(UITypeEditor)), TypeConverter(typeof(StyleConverter))]
        public string LnumStyle { get; set; }
        /// <summary>
        /// Gets or sets the op style.
        /// </summary>
        /// <value>The op style.</value>
        [LocalizedCategory("CategoryAttribute_Styles"), LocalizedDescription("DescriptionAttribute_OpStyle"), Editor(typeof(StyleEditor), typeof(UITypeEditor)), TypeConverter(typeof(StyleConverter))]
        public string OpStyle { get; set; }
        /// <summary>
        /// Gets or sets the preproc style.
        /// </summary>
        /// <value>The preproc style.</value>
        [LocalizedCategory("CategoryAttribute_Styles"), LocalizedDescription("DescriptionAttribute_PreprocStyle"), Editor(typeof(StyleEditor), typeof(UITypeEditor)), TypeConverter(typeof(StyleConverter))]
        public string PreprocStyle { get; set; }
        /// <summary>
        /// Gets or sets the pre style.
        /// </summary>
        /// <value>The pre style.</value>
        [LocalizedCategory("CategoryAttribute_Styles"), LocalizedDescription("DescriptionAttribute_PreStyle"), Editor(typeof(StyleEditor), typeof(UITypeEditor)), TypeConverter(typeof(StyleConverter))]
        public string PreStyle { get; set; }
        /// <summary>
        /// Gets or sets the rem style.
        /// </summary>
        /// <value>The rem style.</value>
        [LocalizedCategory("CategoryAttribute_Styles"), LocalizedDescription("DescriptionAttribute_RemStyle"), Editor(typeof(StyleEditor), typeof(UITypeEditor)), TypeConverter(typeof(StyleConverter))]
        public string RemStyle { get; set; }
        /// <summary>
        /// Gets or sets the STR style.
        /// </summary>
        /// <value>The STR style.</value>
        [LocalizedCategory("CategoryAttribute_Styles"), LocalizedDescription("DescriptionAttribute_StrStyle"), Editor(typeof(StyleEditor), typeof(UITypeEditor)), TypeConverter(typeof(StyleConverter))]
        public string StrStyle { get; set; }
        /// <summary>
        /// Gets or sets the wrapper style.
        /// </summary>
        /// <value>The wrapper style.</value>
        [LocalizedCategory("CategoryAttribute_Styles"), LocalizedDescription("DescriptionAttribute_WrapperStyle"), Editor(typeof(StyleEditor), typeof(UITypeEditor)), TypeConverter(typeof(StyleConverter))]
        public string WrapperStyle { get; set; }
        /// <summary>
        /// Gets the style map.
        /// </summary>
        /// <value>The style map.</value>
        [Browsable(false), XmlIgnore]
        public Hashtable StyleMap
        {
            get
            {
                var styleMap = new Hashtable
                {
                    {"alt", AltStyle},
                    {"alteven", AltevenStyle},
                    {"asp", AspStyle},
                    {"attr", AttrStyle},
                    {"cls", ClsStyle},
                    {"csharpcode", ((LineNumbers || AlternateLines) ? CodeStyle : PreStyle)},
                    {"csharpcode-wrapper", WrapperStyle},
                    {"html", HtmlStyle},
                    {"kwrd", KwrdStyle},
                    {"lnum", LnumStyle},
                    {"op", OpStyle},
                    {"preproc", PreprocStyle},
                    {"rem", RemStyle},
                    {"str", StrStyle}
                };
                return styleMap;
            }
        }
        #endregion Properties

        #region Initialization
        /// <summary>
        /// Initializes a new instance of the <see cref="StyleConfig"/> class.
        /// </summary>
        public StyleConfig()
        {
            // Format
            AlternateLines = true;
            EmbedStyles = true;
            LineNumbers = true;
            UseContainer = true;
            // Styles
            AttrStyle = "color: #ff0000;";
            AspStyle = "background-color: #ffff00;";
            AltStyle = "background-color: #f4f4f4; font-family: 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt; border-style: none; color: black; overflow: visible; padding: 0px; width: 100%; margin: 0em; background-color: white; direction: ltr; text-align: left;";
            AltevenStyle = "background-color: #f4f4f4; font-family: 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt; border-style: none; color: black; overflow: visible; padding: 0px; width: 100%; margin: 0em; direction: ltr; text-align: left;";
            ClsStyle = "color: #cc6633;";
            CodeStyle = "background-color: #f4f4f4; font-family: 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt; border-style: none; color: black; overflow: visible; padding: 0px; width: 100%; direction: ltr; text-align: left;";
            HtmlStyle = "color: #800000;";
            KwrdStyle = "color: #0000ff;";
            LnumStyle = "color: #606060;";
            OpStyle = "color: #0000c0;";
            PreprocStyle = "color: #cc6633;";
            PreStyle = "background-color: #f4f4f4; font-family: 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt; border-style: none; color: black; overflow: visible; padding: 0px; width: 100%; margin: 0em; direction: ltr; text-align: left;";
            RemStyle = "color: #008000;";
            StrStyle = "color: #006080;";
            WrapperStyle = "background-color: #f4f4f4; font-family: 'Courier New', Courier, Monospace; font-size: 8pt; line-height: 12pt; border: solid 1px silver; cursor: text; margin: 20px 0px 10px 0px; max-height: 200px; overflow: auto; padding: 4px; width: 97.5%; direction: ltr; text-align: left;";
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="StyleConfig"/> class.
        /// </summary>
        /// <param name="copy">The copy.</param>
        public StyleConfig(StyleConfig copy)
        {
            // Format
            AlternateLines = copy.AlternateLines;
            EmbedStyles = copy.EmbedStyles;
            LineNumbers = copy.LineNumbers;
            UseContainer = copy.UseContainer;
            // Styles
            AttrStyle = copy.AttrStyle;
            AspStyle = copy.AspStyle;
            AltStyle = copy.AltStyle;
            AltevenStyle = copy.AltevenStyle;
            ClsStyle = copy.ClsStyle;
            CodeStyle = copy.CodeStyle;
            HtmlStyle = copy.HtmlStyle;
            KwrdStyle = copy.KwrdStyle;
            LnumStyle = copy.LnumStyle;
            OpStyle = copy.OpStyle;
            PreprocStyle = copy.PreprocStyle;
            PreStyle = copy.PreStyle;
            RemStyle = copy.RemStyle;
            StrStyle = copy.StrStyle;
            WrapperStyle = copy.WrapperStyle;
        }
        #endregion Initialization
    }
}
